﻿// Class1.cpp
#include "pch.h"
#include "PlayerSource.h"

using namespace WPlayerSource;
using namespace Platform;

PlayerSource::PlayerSource()
{
	Init();
}

bool PlayerSource::Init()
{
	bool bRet = false;

	HRESULT hr = MFStartup(MF_VERSION);
	if (S_OK != hr)
	{
		return false;
	}



done:
	/*SafeRelease(&pSourceResolver);
	SafeRelease(&pSource);*/
	return true;

}

bool PlayerSource::CreateSource(String^ sURL)
{
	HRESULT hr = NULL;
	//Create Media Source
	IMFSourceResolver* pSourceResolver = NULL;
	hr = MFCreateSourceResolver(&pSourceResolver);

	if (FAILED(hr))
	{
		goto done;
	}

	LPCWSTR sourceURL = sURL->Data();
	MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
	IUnknown* pSource = NULL;
	hr = pSourceResolver->CreateObjectFromURL(sourceURL, MF_RESOLUTION_MEDIASOURCE, NULL, &ObjectType, &pSource);

	if (FAILED(hr))
	{
		goto done;
	}

	IMFMediaType **ppMediaType = NULL;
	MFCreateMediaType(ppMediaType);

	DWORD dwSteamIdendifier = NULL;
	DWORD dwMediaType = NULL;

	IMFStreamDescriptor **ppStreamDescriptor = NULL;
	MFCreateStreamDescriptor(dwSteamIdendifier, dwMediaType, ppMediaType, ppStreamDescriptor);

	IMFMediaTypeHandler **ppMediaTypeHandle = NULL;

done:
	/*SafeRelease(&pSourceResolver);
	SafeRelease(&pSource);*/
	return true;
}

PlayerSource::~PlayerSource()
{
	HRESULT hr = MFShutdown();
}
